#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10, M = N;
int n, k, m;
int w[N], p[N];
int st[N];
int ans1;
struct node
{
	int a, b, w;
}S[M];
int cmp(node a, node b)
{
	return a.w > b.w;
}

int find(int x)
{
	if (x != p[x])p[x] = find(p[x]);
	return p[x];
}
void kruskal()
{
	sort(S + 1, S + m + 1, cmp);
	for (int i = 1; i <= n; i++)p[i] = i;
	for (int i = 1; i <= m; i++) {
		int a = S[i].a;
		int b = S[i].b;
		int a1 = find(a);
		int b1 = find(b);
		if (st[a1] && st[b1])continue;	
		p[a1] = b1;
		ans1 += S[i].w;
		if (st[a1])st[b1] = 1;
		else if (st[b1])st[a1] = 1;
		/*int ans = st[a1] + st[b1];
		if (ans <= 1 && a1 != b1) {
			ans1 += S[i].w;
			p[a1] = b1;
		}
		if (st[a])st[a1]++;
		if (st[b])st[b1]++;*/
	}
}
int main()
{
	cin >> n >> k;
	m = n - 1;
	for (int i = 1; i <= k; i++) {
		cin >> w[i];
		w[i]++;
		st[w[i]] = 1;
	}
	LL sum = 0;
	for (int i = 1; i <= n - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a++, b++;
		S[i] = { a,b,c };
		sum += c;
	}
	kruskal();
	//cout << "ans1==" << ans1 << endl;
	cout << sum - ans1 << endl;
	return 0;
}